package datamodels

import "micro-oauth/datamodels/enum"

type Permission struct {
	MyGormModel
	PartnerId   uint64 `json:"partner_id,string" gorm:"index;unique_index:_p_code_partner_id_uc"`
	ParentId    uint64 `json:"parent_id,string" gorm:"index;"`
	Name        string `json:"name" gorm:"size:100;index"`
	Code        string `json:"code" gorm:"size:100;unique_index:_p_code_partner_id_uc"`
	Description string `json:"description" gorm:"size:255"`
	Remark      string `json:"remark" gorm:"type:text"`
	APIs        []*API `json:"apis" gorm:"many2many:permission_api_relation"`
	Content 	Json	`json:"content" gorm:"type: jsonb not null default '{}'::jsonb"`
}

type API struct {
	MyGormModel
	PartnerId   uint64          `json:"partner_id,string" gorm:"index;unique_index:_api_code_partner_id_uc"`
	Name        string          `json:"name" gorm:"size:100;index"`
	Code        string          `json:"code" gorm:"size:100;unique_index:_api_code_partner_id_uc"`
	URL         string          `json:"url" gorm:"size:255"`
	Method      enum.MethodType `json:"method" gorm:"size:100"`
	Description string          `json:"description" gorm:"size:255"`
	Remark      string          `json:"remark" gorm:"type:text"`
	PermissionId uint64			`json:"permission_id" gorm:"-"`
}

//grpc-gateway rpc---http relation
type Method struct {
	MyGormModel
	PartnerId   uint64 `json:"partner_id,string" gorm:"index;"`
	ScopeId   	uint64 `json:"scope_id,string" gorm:"index;"`
	ServiceName string `json:"service_name" gorm:"index：idx_service_method;"`
	MethodType  string `json:method_type`
	MethodName  string `json:"method_name" gorm:"index：idx_service_method;"`
	Url         string `json:"url"`
}
